﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using ReceiptPrint.Models;


namespace ReceiptPrint.ViewModels.ExcelFileVMs
{
    public partial class ExcelFileListVM : BasePagedListVM<ExcelFile_View, ExcelFileSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"", dialogHeight:700,dialogWidth: 600).SetMax(false),
                this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "",dialogHeight:700, dialogWidth: 600).SetMax(false),
                this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "",dialogHeight:700, dialogWidth: 600).SetMax(false),
                 this.MakeAction("Template","Index","详情","详情", GridActionParameterTypesEnum.SingleId,dialogWidth:500)
                .SetShowInRow(true).SetHideOnToolBar(true),
                 this.MakeAction("ExcelFile","ExportFile","导出","导出", GridActionParameterTypesEnum.SingleId,dialogHeight:700,dialogWidth:500)
                .SetShowInRow(true).SetHideOnToolBar(true).SetShowDialog(false).SetPromptMessage("确定要导出吗？"),

                //this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.Details, Localizer["Sys.Details"], "", dialogWidth: 800),
                //this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.BatchEdit, Localizer["Sys.BatchEdit"], "", dialogWidth: 800),
                //this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "", dialogWidth: 800),
                //this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.Import, Localizer["Sys.Import"], "", dialogWidth: 800),
                //this.MakeStandardAction("ExcelFile", GridActionStandardTypesEnum.ExportExcel, Localizer["Sys.Export"], ""),
            };
        }


        protected override IEnumerable<IGridColumn<ExcelFile_View>> InitGridHeader()
        {
            return new List<GridColumn<ExcelFile_View>>{
                this.MakeGridHeader(x => x.Name),
                 this.MakeGridHeader(x => x.FontSize),
                this.MakeGridHeader(x => x.FileId).SetFormat(FileIdFormat),
                this.MakeGridHeaderAction(width: 300)
            };
        }
        private List<ColumnFormatInfo> FileIdFormat(ExcelFile_View entity, object val)
        {
            return new List<ColumnFormatInfo>
            {
                ColumnFormatInfo.MakeDownloadButton(ButtonTypesEnum.Button,entity.FileId),
                //ColumnFormatInfo.MakeViewButton(ButtonTypesEnum.Button,entity.FileId,640,480),
            };
        }


        public override IOrderedQueryable<ExcelFile_View> GetSearchQuery()
        {
            var query = DC.Set<ExcelFile>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .Select(x => new ExcelFile_View
                {
				    ID = x.ID,
                    Name = x.Name,
                    FontSize = x.FontSize,
                    FileId = x.FileId,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class ExcelFile_View : ExcelFile{

    }
}
